//
// File: fft.cpp
//
// MATLAB Coder version            : 5.4
// C/C++ source code generated on  : 21-Mar-2025 17:03:22
//

// Include Files
#include "fft.h"
#include "FFTImplementationCallback.h"
#include "rt_nonfinite.h"
#include "coder_array.h"

// Function Definitions
//
// Arguments    : const ::coder::array<double, 2U> &x
//                double varargin_1
//                ::coder::array<creal_T, 2U> &y
// Return Type  : void
//
namespace coder {
void fft(const ::coder::array<double, 2U> &x, double varargin_1,
         ::coder::array<creal_T, 2U> &y)
{
  array<creal_T, 1U> yCol;
  array<double, 2U> costab;
  array<double, 2U> sintab;
  array<double, 2U> sintabinv;
  array<double, 1U> b_x;
  int N2blue;
  int nRows;
  if ((x.size(1) == 0) || (static_cast<int>(varargin_1) == 0)) {
    nRows = static_cast<int>(varargin_1);
    y.set_size(1, nRows);
    for (N2blue = 0; N2blue < nRows; N2blue++) {
      y[N2blue].re = 0.0;
      y[N2blue].im = 0.0;
    }
  } else {
    boolean_T useRadix2;
    useRadix2 = ((static_cast<int>(varargin_1) > 0) &&
                 ((static_cast<int>(varargin_1) &
                   (static_cast<int>(varargin_1) - 1)) == 0));
    internal::FFTImplementationCallback::get_algo_sizes(
        static_cast<int>(varargin_1), useRadix2, &N2blue, &nRows);
    internal::FFTImplementationCallback::generate_twiddle_tables(
        nRows, useRadix2, costab, sintab, sintabinv);
    if (useRadix2) {
      nRows = x.size(1);
      b_x = x.reshape(nRows);
      nRows = static_cast<int>(varargin_1);
      yCol.set_size(nRows);
      if (static_cast<int>(varargin_1) > b_x.size(0)) {
        yCol.set_size(nRows);
        for (N2blue = 0; N2blue < nRows; N2blue++) {
          yCol[N2blue].re = 0.0;
          yCol[N2blue].im = 0.0;
        }
      }
      if (static_cast<int>(varargin_1) != 1) {
        internal::FFTImplementationCallback::doHalfLengthRadix2(
            b_x, yCol, static_cast<int>(varargin_1), costab, sintab);
      } else {
        nRows = b_x.size(0);
        if (nRows > 1) {
          nRows = 1;
        }
        yCol[0].re = b_x[nRows - 1];
        yCol[0].im = 0.0;
      }
    } else {
      nRows = x.size(1);
      b_x = x.reshape(nRows);
      internal::FFTImplementationCallback::dobluesteinfft(
          b_x, N2blue, static_cast<int>(varargin_1), costab, sintab, sintabinv,
          yCol);
    }
    y.set_size(1, static_cast<int>(varargin_1));
    nRows = static_cast<int>(varargin_1);
    for (N2blue = 0; N2blue < nRows; N2blue++) {
      y[N2blue] = yCol[N2blue];
    }
  }
}

//
// Arguments    : const ::coder::array<double, 2U> &x
//                ::coder::array<creal_T, 2U> &y
// Return Type  : void
//
void fft(const ::coder::array<double, 2U> &x, ::coder::array<creal_T, 2U> &y)
{
  array<creal_T, 1U> yCol;
  array<double, 2U> costab;
  array<double, 2U> sintab;
  array<double, 2U> sintabinv;
  array<double, 1U> b_x;
  int N2blue;
  int nRows;
  if (x.size(1) == 0) {
    y.set_size(1, 0);
  } else {
    boolean_T useRadix2;
    useRadix2 = ((x.size(1) & (x.size(1) - 1)) == 0);
    internal::FFTImplementationCallback::get_algo_sizes(x.size(1), useRadix2,
                                                        &N2blue, &nRows);
    internal::FFTImplementationCallback::generate_twiddle_tables(
        nRows, useRadix2, costab, sintab, sintabinv);
    if (useRadix2) {
      nRows = x.size(1);
      b_x = x.reshape(nRows);
      nRows = x.size(1);
      yCol.set_size(nRows);
      if (nRows > b_x.size(0)) {
        yCol.set_size(nRows);
        for (N2blue = 0; N2blue < nRows; N2blue++) {
          yCol[N2blue].re = 0.0;
          yCol[N2blue].im = 0.0;
        }
      }
      if (nRows != 1) {
        internal::FFTImplementationCallback::doHalfLengthRadix2(
            b_x, yCol, nRows, costab, sintab);
      } else {
        nRows = b_x.size(0);
        if (nRows > 1) {
          nRows = 1;
        }
        yCol[0].re = b_x[nRows - 1];
        yCol[0].im = 0.0;
      }
    } else {
      nRows = x.size(1);
      b_x = x.reshape(nRows);
      internal::FFTImplementationCallback::dobluesteinfft(
          b_x, N2blue, x.size(1), costab, sintab, sintabinv, yCol);
    }
    y.set_size(1, x.size(1));
    nRows = x.size(1);
    for (N2blue = 0; N2blue < nRows; N2blue++) {
      y[N2blue] = yCol[N2blue];
    }
  }
}

} // namespace coder

//
// File trailer for fft.cpp
//
// [EOF]
//
